home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / BSHALT.C < prev    next >
C/C++ Source or Header  |  1993-08-11  |  4KB  |  129 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    bshalt.c
  5. //   Title:    Base library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains code to halt an application on a serious error.
  25. //    No clean-up is done. The application is simply terminated!
  26. //
  27. //    The code in this module should be written entirely in C. 
  28. //    Do not use any C++ constructs.
  29. //
  30. //    This module is portable to:
  31. //        DOS 3.X+
  32. //        MS Windows 3.X+
  33. //        OS/2 2.X+
  34. //        OS/2 2.0 PM
  35. //        SCO UNIX.
  36. //
  37. //    The following compilers are supported:
  38. //        MSC 6.0A
  39. //        MSC/C++ 7.0
  40. //        Borland C++ 3.1 for DOS
  41. //        Borland C++ 1.0 for OS/2 2.X
  42. //        SCO UNIX cc
  43. //
  44. //----------------------------------------------------------------------------
  45. #include <bs.h>
  46.  
  47.  
  48. //----------------------------------------------------------------------------
  49. //   Description:    Display a VERY serious fatal error message.
  50. //                          Text is written to stdout and program aborts with
  51. //                        no clean-up
  52. //                          Program aborts with exit code 99.
  53. //    Parameters:    pcsz                Error message text
  54. //       Returns:    FALSE
  55. //----------------------------------------------------------------------------
  56. BOOL FN_E Halt_Debug(PCSZ pcsz)
  57. {
  58.     FILE *fileLog = fopen("halt.log", "a+t");
  59.     CHAR szContext[IOBUF_SIZE];
  60.     SIZET i;
  61.  
  62.     if (!pcsz)
  63.         pcsz = "Unknown fatal internal application error.";
  64.  
  65.     if (fileLog != NULL)
  66.         {
  67.         DebugContext(szContext, TRUE);
  68.         fprintf(fileLog,
  69.            "%s"
  70.             "Program Halted!\n"
  71.             "%s\n",
  72.             szContext, pcsz);
  73.  
  74.         fclose(fileLog);
  75.         }
  76.     DebugContext(szContext, FALSE);
  77. #if OS_WINDOWS
  78.     strcat(szContext, pcsz);
  79.     MessageBox(NULL, szContext, "HALT !", MB_ICONEXCLAMATION|MB_OK|MB_TASKMODAL);
  80. #elif OS_PM
  81.  
  82. #else
  83.         fprintf(stderr,
  84.            "\n"
  85.            "%s"
  86.             "Program Halted!\n%s\n"
  87.             "\n",
  88.             szContext, pcsz);
  89. #endif
  90.  
  91.     for (i = 3; i < 100; ++i)                // Brute force method of closing all files.
  92.         close(i);
  93.  
  94. #if OS_DOS && COMPILER_BORLAND
  95.     CtrlCTerminate();
  96.     PrintScreenTerminate();
  97.     CritErrTerminate();
  98. #endif
  99.  
  100.     _exit(99);
  101. #if COMPILER_BORLAND && OS_DOS
  102.     _asm {                                        // Simply KILL the program. No more clean-up
  103.         mov    ax, 4CFFh                        //  or anything
  104.         int     21h
  105.         }
  106. #endif
  107.     return FALSE;
  108. }
  109.  
  110.  
  111. //----------------------------------------------------------------------------
  112. //   Description:    Run standard test suite
  113. //    Parameters:    sTest        Test to run.
  114. //                                        0        Run all default tests (except).
  115. //                                    Default is 0.
  116. //       Returns:    TRUE if successful.
  117. //----------------------------------------------------------------------------
  118. #if COMPILE_TEST
  119. BOOL FN HaltTest(SHORT sTest)
  120. {
  121.     NOTUSED(sTest);
  122.     Halt("This is a test error");
  123.     return TRUE;
  124. }
  125. #endif
  126. //----------------------------------------------------------------------------
  127. //------------------------------- End of File --------------------------------
  128. //----------------------------------------------------------------------------
  129.